<template>
  <div class="content">

    <table class="myTable">
      <thead>
        <tr>
          <th colspan="2">
            修改密码
          </th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td class="textRight">
            旧密码
          </td>
          <td class="textLeft">
            <input type="password" v-model="changePwdForm.oldpassword">
          </td>
        </tr>
        <tr>
          <td class="textRight">
            新密码
          </td>
          <td class="textLeft">
            <input type="password" v-model="changePwdForm.password">＊6-20字符必须由大小写字母和数字组合组成
          </td>
        </tr>
        <tr>
          <td class="textRight">
            确认新密码
          </td>
          <td class="textLeft">
            <input type="password" v-model="changePwdForm.repassword">
          </td>
        </tr>
      </tbody>
    </table>

    <div class="bottomBtns">
      <button @click="handleChange">确认</button>
      <button @click="restForm">重置</button>
    </div>

  </div>
</template>

<script>
  import { Message } from 'element-ui'

  export default {
    name: 'changepwd',
    data() {
      return {
        loading: false,
        pwdType: 'password',
        errorMsg: '',
        changePwdForm: {
          oldpassword: '',
          password: '',
          repassword: '',
        },
      }
    },

    methods: {
      restForm() {
        this.changePwdForm.oldpassword = ''
        this.changePwdForm.password = ''
        this.changePwdForm.repassword = ''
      },
      checkConfirm(param) {
        // 验证新密码是否一致
      },
      handleChange() {
        this.loading = true
        this.$store
          .dispatch('MemberChangePwd', { ChangePwdForm: this.changePwdForm })
          .then(response => {
            this.loading = false
            this.errorMsg = ''
            if (response === true) {
              // 修改成功
              Message.success('修改成功,请重新登录')
              // 清空状态,重新登录
              this.$store
                .dispatch('FedLogOut')
                .then(this.$router.push({ path: '/login' }))
            } else {
              // 修改失败
              alert(Object.values(response)[0].toString()) // 取第一个错误信息
            }
          })
          .catch(() => {
            this.loading = false
          })
      },
    },
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .content{
    padding: 5px;
    margin-left: 190px;
    width: 884px;
  }
  .myTable{
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    margin: 2px  0;
    font-size:12px;
    box-sizing: inherit;
  }
  .myTable th{
    height: 25px;
    text-align: center;
    color: #131950;
    font-weight: bold;
    line-height: 25px;
    padding-left: 10px;
    padding-right: 10px;
    margin: 0;
  }
  .myTable td{
    color: #131950;
    line-height: 25px;
    padding: 5px;
    text-align: center;
  }
  .textLeft{
    text-align: left !important;
    text-indent: 22px;
  }
  .textRight{
    text-align: right !important;
    width: 231px;
    padding-right: 36px !important;
  }
  .bottomBtns{
    text-align: center;
    margin-top: 20px;
  }
  .bottomBtns button{
    width: 66px;
    height: 18px;
    line-height: 18px;
    margin-right: 5px;
    color: #fff;
    letter-spacing: 3px;
  }
  .bottomBtns button:hover{
    color: #FFE400;
    font-weight: bold;
  }
</style>
